﻿using System;
using System.Collections.Generic;

namespace MGAS.Model.Entity
{
    class SensorData : ISensorData
    {
        public static SensorData Create(byte id)
        {
            return new SensorData(id);
        }

        public static SensorData CreateData(byte id, int value, PressureUnit unit, PressureStatus status)
        {
            return new SensorData(id) { Value = value, Unit = unit, Status = status };
        }

        public static SensorData CreateErrorData(byte id)
        {
            return new SensorData(id) { Status = PressureStatus.Error, Unit = PressureUnit.Unknown };
        }

        public static SensorData CreateUnknownData(byte id)
        {
            return new SensorData(id) { Status = PressureStatus.Unknown, Unit = PressureUnit.Unknown };
        }

        private SensorData(byte id)
        {
            _id = id;
        }

        private byte _id;
        public byte ID
        {
            get { return _id; }
        }

        public virtual int Value
        {
            get;
            set;
        }

        public virtual PressureUnit Unit
        {
            get;
            set;
        }

        public virtual PressureStatus Status
        {
            get;
            set;
        }

        private void CheckMeta()
        {
            if (!Meta)
                throw new InvalidOperationException("Meta information is not valid.");
        }

        private int _building;
        public int Building
        {
            get
            {
                CheckMeta();
                return _building;
            }
            set { _building = value; }
        }

        private int _floor;
        public int Floor
        {
            get
            {
                CheckMeta();
                return _floor;
            }
            set
            {
                _floor = value;
            }
        }

        private int _lineNumber;
        public int LineNumber
        {
            get
            {
                CheckMeta();
                return _lineNumber;
            }
            set
            {
                CheckMeta();
                _lineNumber = value;
            }
        }


        public bool Meta
        {
            get;
            set;
        }


        public GasType Type
        {
            get;
            set;
        }
    }
}
